var frm = 'docForm';

function validateNumber(evt){
    if (isNumberKey(evt)){
        return true;
    }else{
        return false;
    }
}

function cleanFiscalName(){
    $(frm + ':fiscalName').value = '';
}

function cleanMemberName(){
    $(frm + ':memberName').value = '';
}

function cleanup(){
    $(frm + ':votePlc').value = '';
    $(frm + ':voteFsln').value = '';                        
    $(frm + ':votePc').value = '';
    $(frm + ':voteYatama').value = '';
    $(frm + ':voteAln').value = '';
    $(frm + ':votePrn').value = '';
    $(frm + ':votePli').value = '';
    $(frm + ':nullVotes').value = '';
    $(frm + ':calcDepositedVotes').value = '';
    $(frm + ':calcValidVotes').value = '';
    $(frm + ':depositedVotes').value = '';
    $(frm + ':validVotes').value = '';
    $(frm + ':nullVotes').value = '';
}
                    
function calc() {

    var votePlc = getValue($(frm + ':votePlc').value);
    var voteFsln = getValue($(frm + ':voteFsln').value);
    var votePc = getValue($(frm + ':votePc').value);
    var voteYatama = getValue($(frm + ':voteYatama').value);
    var voteAln = getValue($(frm + ':voteAln').value);
    var votePrn = getValue($(frm + ':votePrn').value);
    var votePli = getValue($(frm + ':votePli').value);
                        
    var nullVotes = getValue($(frm + ':nullVotes').value);
    if (nullVotes == 0 || nullVotes == null)
    {
        nullVotes = 0;
    }

    var validVotes = votePlc + voteFsln + votePc + voteYatama + voteAln + votePrn + votePli;
    var totalVotes = validVotes + nullVotes;
                        
    $(frm + ':calcDepositedVotes').innerHTML = totalVotes;
    $(frm + ':calcValidVotes').innerHTML = validVotes;
    $(frm + ':depositedVotes').value = totalVotes;
    $(frm + ':validVotes').value = validVotes;
    $(frm + ':nullVotes').value = nullVotes;
                        
    if(totalVotes > 100){
        alert('Suma de votos mayor a 100');
        return fail;
    }
    return true;
} 
                    
function calcNulls() {
                        
    var votePlc = getValue($(frm + ':votePlc').value);
    var voteFsln = getValue($(frm + ':voteFsln').value);
    var votePc = getValue($(frm + ':votePc').value);
    var voteYatama = getValue($(frm + ':voteYatama').value);
    var voteAln = getValue($(frm + ':voteAln').value);
    var votePrn = getValue($(frm + ':votePrn').value);
    var votePli = getValue($(frm + ':votePli').value);
                        
    var depositedVotes = getValue($(frm + ':depositedVotes').value);
    var validVotes = getValue($(frm + ':validVotes').value);
                        
    var totalNulls = depositedVotes - validVotes;
    var calcDepositVotes = votePlc + voteFsln + votePc + voteYatama + voteAln + votePrn + votePli + totalNulls;
                        
    if (0 > totalNulls){
        alert('Votos nulos deben ser mayor a cero');
        return false;
    }
                        
    $(frm + ':nullVotes').value = totalNulls;
    $(frm + ':calcDepositedVotes').innerHTML = calcDepositVotes;
    return true;
}
                    
function calcNullSingle(){
                        
    var votePlc = getValue($(frm + ':votePlc').value);
    var voteFsln = getValue($(frm + ':voteFsln').value);                        
    var votePc = getValue($(frm + ':votePc').value);
    var voteYatama = getValue($(frm + ':voteYatama').value);
    var voteAln = getValue($(frm + ':voteAln').value);
    var votePrn = getValue($(frm + ':votePrn').value);
    var votePli = getValue($(frm + ':votePli').value);
                        
    var calcValidVotes = votePlc + voteFsln + votePc + voteYatama + voteAln + votePrn + votePli;
    var unformatedNullVotes = $(frm + ':nullVotes').value;
    var nullVotes = getValue($(frm + ':nullVotes').value);
                        
    var vSign = unformatedNullVotes.substr(0,1);
                
    if(vSign == '-'){
        nullVotes = nullVotes * -1;
    }
                        
    if (0 > nullVotes){
        alert('Votos nulos deben ser mayor a cero');
        return false;
    }
                        
    var calcDepositedVotes = calcValidVotes + nullVotes;
    $(frm + ':calcDepositedVotes').innerHTML = calcDepositedVotes;
    $(frm + ':depositedVotes').value = calcDepositedVotes;
    $(frm + ':nullVotes').value = nullVotes;
    return true;
}
                    
function validations(){
                        
    var votePlc = getValue($(frm + ':votePlc').value);
    var voteFsln = getValue($(frm + ':voteFsln').value);
    var votePc = getValue($(frm + ':votePc').value);
    var voteYatama = getValue($(frm + ':voteYatama').value);
    var voteAln = getValue($(frm + ':voteAln').value);
    var votePrn = getValue($(frm + ':votePrn').value);
    var votePli = getValue($(frm + ':votePli').value);
                        
    var depositedVotes = getValue($(frm + ':depositedVotes').value);
    var formValidVotes = getValue($(frm + ':validVotes').value);
                        
    var unformatedNullVotes = $(frm + ':nullVotes').value;
    var nullVotes = getValue($(frm + ':nullVotes').value);
                        
    var vSign = unformatedNullVotes.substr(0,1);
                
    if(vSign == '-'){
        nullVotes = nullVotes * -1;
    }
                        
    if (nullVotes == 0 || nullVotes == null)
    {
        nullVotes = 0;
    }

    var validVotes = votePlc + voteFsln + votePc + voteYatama + voteAln + votePrn + votePli;
    var totalVotes = validVotes + nullVotes;
                        
    if(totalVotes > 100){
        alert('Suma de votos invalida');
        return fail;
    }
    if (validVotes == 0 || totalVotes == 0){
        alert('Suma de votos debe ser diferente de cero');
        return false;
    }
    if (0 > validVotes){
        alert('Votos validos debe ser mayor a cero');
        return false;
    }
                        
    if (0 > totalVotes){
        alert('Votos validos debe ser mayor a cero');
        return false;
    }

    if (0 > nullVotes){
        alert('Votos nulos deben ser mayor a cero');
        return false;
    }
                        
    if(totalVotes != depositedVotes){
        alert('Suma de votos depositados invalida');
        return false;
    }
                        
    if(validVotes != formValidVotes){
        alert('Suma de votos validos invalida');
        return false;
    }
    return true;
}